﻿@{
    TempData["subMenu-check"] = new string[] { "User", "ManageUserMedals" };
    ViewData["Title"] = new string[] { "勋章授予记录" };
    var userAwardStatus = ViewData.Get<List<SelectListItem>>("userAwardStatus", null);
    var medals = ViewData.Get<List<SelectListItem>>("medals", null);
    var medalId = ViewData.Get("medalId", 0);
}
<div class="row tn-page-heading tn-mb-10">
    <div class="col-xs-12">
        <h3><a href="@SiteUrls.Instance().ManageUserMedals()">勋章管理</a> / 勋章授予记录</h3>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body">
        <div class="form-inline tn-tool-column">
            <div class="form-group">
                状态&nbsp;&nbsp;@Html.DropDownList("userAwardStatus", userAwardStatus, "全部", new { @class = "form-control searchPara" })
            </div>
            <div class="form-group">
                勋章&nbsp;&nbsp;@Html.DropDownList("medalId", medals, "全部", new { @class = "form-control searchPara" })
            </div>
            <div class="form-group">
                @Html.UserSelector("userId", null, mode: UserOrOrgSelectorMode.User, selectionNum: 50, innerText: "选择用户", validation: true, sourceUrl: SiteUrls.Instance().GetAllOguUser())
            </div>
            <div class="form-group pull-right">
                <button class="btn btn-primary" id="medalsearch" type="button">搜索</button>
            </div>
        </div>
    </div>
</div>
<div class="panel panel-default">
    <div class="panel-body" id="_ListMedaltoUsers">
    </div>
</div>
<script>
    require(['jquery', 'tnlayer', 'userSelector','page'], function ($, tnlayer) {
        $(function () {
            $(".tn-choice-add").removeClass("tn-choice-add");
            if (@medalId > 0)
            {
                $("#medalId").val("@medalId");
            }
            getMedaltoUser();
        });
        $(document).on("click", "#medalsearch", function () {
            getMedaltoUser();
        }).on("change", ".searchPara", function () {
            getMedaltoUser();
        }).on("click", ".deletemedaltouser", function () {
            //删除记录
            var medaltoUserId = $(this).data("medaltouserid");
            layer.confirm("确定删除么？", {
                btn: ['确认', '取消'],//按钮
                scrollbar: false
            }, function () {
                var url = '@CachedUrlHelper.Action("DeleteMedaltoUser", "ControlPanel")';
                $.post(url, { medaltoUserId: medaltoUserId }, function (data) {
                    if (data.MessageType == 1) {
                        getMedaltoUser($("#pageIndex").val());
                        layer.msg(data.MessageContent, { icon: 1 });
                    }
                    else {
                        layer.msg(data.MessageContent, { icon: 2 });
                    }
                });
            });
        }).on("click", ".medaltouserdeal", function () {
            //点击拒绝、批准、收回勋章操作
            var $this = $(this);
            var medaltoUserId = $this.data("medaltouserid");
            var method = $this.data("method");
            var url = '@CachedUrlHelper.Action("ChangeMedaltoUserStatus", "ControlPanel")';
            $.post(url, { medaltoUserId: medaltoUserId, method: method }, function (data) {
                if (data.MessageType == 1) {
                    getMedaltoUser($("#pageIndex").val());
                    layer.msg(data.MessageContent, { icon: 1 });
                }
                else {
                    layer.msg(data.MessageContent, { icon: 2 });
                }
            });
            
        });
        //获取勋章授予记录列表
        function getMedaltoUser(pageIndex) {
            var url = '@CachedUrlHelper.Action("_ListMedaltoUsers", "ControlPanel")?t=' + (new Date).getTime();
            var para = $(".searchPara").serializeArray();
            var userIds = [];
            var $userInput = $("input[name='userId']");
            if ($userInput.length > 0)
            {
                $userInput.each(function () {
                    userIds.push($(this).val());
                });
                para.push({ "name": "userId", "value": userIds.join(",") });
            }
            if (pageIndex > 0)
            {
                para.push({ "name": "pageIndex", "value": pageIndex })
            }
            $.get(url, para, function (data) {
                $("#_ListMedaltoUsers").html(data);
            })
        }
    })
</script>
